package com.wc.alorithm_luogu._动态规划._线性DP.方格取数;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/8 20:08
 * @description https://www.luogu.com.cn/problem/P1004
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 15;
    static int[][] g = new int[N][N];
    // f[k][i][j] k = x1 + y1 = x2 + y2,一共走了k步, 第一个像右走了i步第二个右走了j步的最大值
    static int[][][] f = new int[N << 1][N][N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        while (sc.hasNext()) {
            int x = sc.nextInt(), y = sc.nextInt(), w = sc.nextInt();
            if (x == 0 || y == 0) break;
            g[x][y] = w;
        }
        for (int k = 2; k <= n << 1; k++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    int first = k - i, second = k - j;
                    if (first < 1 || first > n || second < 1 || second > n) continue;
                    int s = g[i][first];
                    if (i != j) s += g[j][second];

                    // 右 右
                    f[k][i][j] = Math.max(f[k][i][j], f[k - 1][i - 1][j - 1] + s);
                    // 右 下
                    f[k][i][j] = Math.max(f[k][i][j], f[k - 1][i - 1][j] + s);
                    // 下 右
                    f[k][i][j] = Math.max(f[k][i][j], f[k - 1][i][j - 1] + s);
                    // 下 下
                    f[k][i][j] = Math.max(f[k][i][j], f[k - 1][i][j] + s);
                }
            }
        }
        out.println(f[n << 1][n][n]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
